/******************************************************************************************
 * Import
 ******************************************************************************************/

// module
import React, {Component} from 'react';
import {View, TouchableHighlight} from 'react-native';
import { Button, Modal, Icon} from 'antd-mobile-rn';

// project
import {
    Page, Content, Text, Row, Header, Footer, Between, Hand, TouchOpacity
} from '../../../../library'
import HttpTemp from "../../../../preset/func/http/httptemp"

/******************************************************************************************
 * Export Class
 ******************************************************************************************/

export default class MyHouse extends Component {

    /*------------------------------------------------------------------------------------
	 * 初始化
	 *-----------------------------------------------------------------------------------*/
	constructor(props) {
        super(props);
        this.Nav = this.props.navigation;

        /**
         * state
         */
		this.state = {
                apply:[],
                house:[],
                default_houseid:null,
		};
    }
    
    componentDidMount(){
        // SplashScreen.hide();
        HttpTemp.get({
            url:"/page/myhouse/list.php",
            success:(res) => {
                let data = res.data;
                console.log(res.data)
                this.setState({
					apply:data.apply,
					house:data.house,
					default_houseid:data.default_houseid,
                })
            }
        })

    }

    /*------------------------------------------------------------------------------------
	 * 自定义方法
	 *-----------------------------------------------------------------------------------*/
    /**
     * 点击撤销弹出弹窗
     */
    showConfirm = ()=>{
        Modal.alert('','撤销房屋申请，您或其他人与该房屋的一切认证关系和权限同时撤销，确定撤销?', [
            { text: '确定', onPress: () => console.log('确定') },
            { text: '取消', onPress: () => console.log('取消'), style: 'cancel' },
          ]);
    }

	/*------------------------------------------------------------------------------------
	 * 渲染
	 *-----------------------------------------------------------------------------------*/
	render() {
		return (
			<Page>

                {/* 内容部分 */}
				<Content my='40' bg='#efeff4' >

                    {/* 房屋信息标题 */}
                    <Row h='40' y='center' px='10'>
                        <Text>房屋信息</Text>
                    </Row>


                    {/* 房屋列表 审核中 */}
                    {this.state.apply.map((item,index)=>{
                        return(
                            <View style={{backgroundColor:'#fff', marginBottom:10}}>
                            <Row mx='10' bb='1 #f0f0f0' px='10' h='40' y='center'>
                                <Between>
                                    <Hand y='center'>
                                        <Text>{item.subdistrict_name}</Text>
                                    </Hand>
                                    <Hand y='center'>
                                        <Text bg='#3e86ea' color='#fff' size='12' px='10' py='4' ra='5'>{item.enum_checked}</Text>
                                    </Hand>
                                </Between>
                            </Row>
                            <Row mx='10' bb='1 #f0f0f0' px='10' h='40' y='center'>
                                <Text>{item.unit_name}</Text>
                            </Row>
                            <Row mx='10' px='10' h='40' y='center'>
                                <Text>{item.enum_apply_status}</Text>
                            </Row>
                        </View>

                        )
                    })}

                    {/* 房屋列表 审核通过 */}
                    {this.state.house.map((item,index)=>{
                        return(
                            <View style={{backgroundColor:'#fff', marginBottom:10}}>
                            <Row mx='10' bb='1 #f0f0f0' px='10' h='40' y='center'>
                                <Between>
                                    <Hand y='center'>
                                        <Text>{item.subdistrict_name}</Text>
                                    </Hand>
                                    <Hand y='center'>
                                        {this.state.default_houseid == item.id ? <Text bg='red' color='#fff' size='12' px='10' py='4' ra='5'>默认</Text>:<Text></Text>}
                                    </Hand>
                                </Between>
                            </Row>
                            <Row mx='10' bb='1 #f0f0f0' px='10' h='40' y='center'>
                                <Text>{item.unit_name}</Text>
                            </Row>
                            <Row mx='10' px='10' h='40' y='center'>
                                <Text>{item.enum_status}</Text>
                            </Row>
                        </View>

                        )
                    })}






                    {/* 撤回按钮 */}
                    {/* <View style={{margin:30}}>
                        <Button 
                            style={{backgroundColor:'#21ac43', borderWidth:0, height:40}}
                            onClick={this.showConfirm } 
                        >
                            <Text color='#fff' size='16'>撤回123</Text>
                        </Button>
                    </View> */}

				</Content>
				
                {/* 头部 */}
				<Header bg='#fff' h='40'>
                    <Between px='10'>
                        <TouchOpacity active={0.6} onPress={(e)=> {
                            this.Nav.goBack()
                        }}>
                            <Icon type='left' size='md' color='#00CC66' />
                        </TouchOpacity>

                        <Text size='17'>我的房屋</Text>
                        <TouchableHighlight
                                onPress={ ()=>{ 
                                    this.Nav.navigate('UserSettingHouseConfirm', {id: this.props.id});
                                 } }
                            >
                            <Text>添加</Text>
                        </TouchableHighlight>

                    </Between>
                </Header>

				{/* 底部 */}
				<Footer bg='#fff' h='40'></Footer>
                
			</Page>
		);
	}
}
